/*
 * NormalizedSteinhartHartModelThermistor.hpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   NormalizedSteinhartHartModelThermistor.hpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   2 sep 2012
 */

#ifndef STEINHARTHARTMODELTHERMISTOR_HPP
#define STEINHARTHARTMODELTHERMISTOR_HPP

#include "Thermistor.hpp"
#include "Resistance.hpp"
#include "Temperature.hpp"

namespace tltgen {

  class NormalizedSteinhartHartModelThermistor : public Thermistor {
  public:
    NormalizedSteinhartHartModelThermistor(Resistance r0, double a, double b, double c, double d);
    virtual ~NormalizedSteinhartHartModelThermistor();

    static bool isValidR0(Resistance r0);
    virtual Resistance getR0() const;

    static bool isValidA(double a);
    virtual double getA() const;

    static bool isValidB(double b);
    virtual double getB() const;

    static bool isValidC(double c);
    virtual double getC() const;

    static bool isValidD(double d);
    virtual double getD() const;

    virtual bool isValidParameterIndex(unsigned int pi) const;
    virtual double getParameterValue(unsigned int pi) const;

    virtual bool isValidResistance(Resistance resistance) const;
    virtual Temperature getTemperature(Resistance resistance) const;

    virtual bool isValidTemperature(Temperature temperature) const;
    virtual Resistance getResistance(Temperature temperature) const;

    virtual void accept(ThermistorVisitor* visitor) const;

    virtual std::ostream &print(std::ostream &stream) const;

  private:
    struct root_finding_params {
      double t;
      NormalizedSteinhartHartModelThermistor* thermistor;
    };

    static double getTemperatureStatic(double r, void *data);

    const Resistance r0;
    const double a;
    const double b;
    const double c;
    const double d;
  };

}

#endif
